class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int n=nums.size();
        vector<int>dp(n);
        int ret=nums[0];
        dp[0]=nums[0];
        for(int i=1;i<n;i++)
        {
            if(nums[i]+dp[i-1]>nums[i])dp[i]=dp[i-1]+nums[i];
            else 
            dp[i]=nums[i];
            ret=max(ret,dp[i]);
        }
        return ret; 
    }
};